home *** CD-ROM | disk | FTP | other *** search
/ C++ für Kids / C++ for kids.iso / Buch / Monstr7a.cpp < prev    next >
C/C++ Source or Header  |  1999-01-29  |  2KB  |  82 lines

  1. //---------------------------------------------------------------------------
  2. #include <vcl\vcl.h>
  3. #pragma hdrstop
  4.  
  5. #include "Monstr7a.h"
  6. //---------------------------------------------------------------------------
  7. #pragma resource "*.dfm"
  8.  
  9. const String Pfad = "c:\\cpp\\buch\\";
  10.  
  11. class TMonster
  12. {
  13. public:
  14.   virtual void Erscheinen(String Bild);
  15. };
  16.  
  17. //---------------------------------------------------------------------------
  18.  
  19. TMonster WerWohl;
  20. bool Modus;
  21. int  Zufall;
  22. TForm1 *Form1;
  23.  
  24. //---------------------------------------------------------------------------
  25. __fastcall TForm1::TForm1(TComponent* Owner)
  26.     : TForm(Owner)
  27. {
  28. }
  29. //---------------------------------------------------------------------------
  30. void TMonster::Erscheinen (String Bild)
  31. {
  32.   String Name = Bild.SubString(1, Bild.Length()-4);
  33.   Form1->Image1->Picture->LoadFromFile (Pfad+Bild);
  34.   Form1->Panel1->Caption = Name;
  35. }
  36. //---------------------------------------------------------------------------
  37. void __fastcall TForm1::FormCreate(TObject *Sender)
  38. {
  39.   randomize ();
  40.   Timer1->Interval = 500;
  41.   Timer1->Enabled = false;
  42.   Modus = true;
  43. }
  44. //---------------------------------------------------------------------------
  45. void __fastcall TForm1::Button1Click(TObject *Sender)
  46. {
  47.   if (Modus)
  48.   {
  49.     Timer1->Enabled = true;
  50.     Button1->Caption = "Stop";
  51.   }
  52.   else
  53.   {
  54.     Timer1->Enabled = false;
  55.     Button1->Caption = "Start";
  56.   }
  57.   Modus = !Modus;
  58. }
  59. //---------------------------------------------------------------------------
  60. void __fastcall TForm1::Timer1Timer(TObject *Sender)
  61. {
  62.   Zufall = random(5);
  63.   switch (Zufall)
  64.   {
  65.     case 0:
  66.       WerWohl.Erscheinen ("Frank.bmp");
  67.       break;
  68.     case 1:
  69.       WerWohl.Erscheinen ("Albert.bmp");
  70.       break;
  71.     case 2:
  72.       WerWohl.Erscheinen ("Sigmund.bmp");
  73.       break;
  74.     case 3:
  75.       WerWohl.Erscheinen ("Jekyll.bmp");
  76.       break;
  77.     case 4:
  78.       WerWohl.Erscheinen ("Hyde.bmp");
  79.   }
  80. }
  81. //---------------------------------------------------------------------------
  82.